package leetcode.code1175;

import leetcode.IDebug;
import leetcode.helper.HelpDebug;

public class Solution implements IDebug {

	int mod = (int) 1e9 + 7;

	public int numPrimeArrangements(int n) {
		int prime = 0;
		for (int i = 1; i <= n; i++) {
			if (isPrime(i)) {
				prime++;
			}
		}
		long ans = factorial(prime);
		ans *= factorial(n - prime);
		return (int) (ans % mod);
	}

	private long factorial(int num) {
		long ans = 1;
		for (int i = 1; i <= num; i++) {
			ans *= i;
			ans %= mod;
		}
		return ans;
	}

	private boolean isPrime(int num) {
		if (num == 2) {
			return true;
		}
		if (num == 1 || num % 2 == 0) {
			return false;
		}
		for (int i = 3; i * i <= num; i += 2) {
			if (num % i == 0 || i * i == num) {
				return false;
			}
		}
		return true;
	}

	@Override
	public void debug4() {
		HelpDebug.compare(12, this.numPrimeArrangements(5));

	}

	@Override
	public void debug3() {
		// TODO Auto-generated method stub

	}

	@Override
	public void debug2() {
		// TODO Auto-generated method stub

	}

	@Override
	public void debug1() {
		// TODO Auto-generated method stub

	}

	public static void main(String[] args) {
		Solution so = new Solution();
		so.debug1();
		so.debug2();
		so.debug3();
		so.debug4();

	}

}
